package ar.com.jendrix.common.exception;

import java.util.ArrayList;
import java.util.List;

import ar.com.jendrix.common.util.Comparator;

@SuppressWarnings("serial")
public abstract class BasicException extends Exception {
	// Properties.
	private List<String> messages;

	/**
	 */
	public BasicException(List<String> messages) {
		this.messages = messages;
	}

	/**
	 */
	public BasicException(String message) {
		this.messages = new ArrayList<String>();
		this.messages.add(message);
	}

	/**
	 */
	public final String getMessage() {
		return getMessagesAsString();
	}

	/**
	 */
	public final String getMessagesAsString() {
		StringBuilder sb = new StringBuilder();
		String ls = System.getProperty("line.separator");

		if (!Comparator.isEmpty(messages)) {
			for (String msg : messages) {
				if (!Comparator.isEmpty(sb.toString())) {
					sb.append(ls);
				}
				sb.append(msg);
			}
		}
		return sb.toString();
	}

	/**
	 */
	public final List<String> getMessages() {
		return messages;
	}
}